package com.iemes.controller.quality;

import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.iemes.annotation.SystemLog;
import com.iemes.controller.index.BaseController;
import com.iemes.entity.CheckMaterialFormMap;
import com.iemes.entity.SuppFilleFromMap;
import com.iemes.mapper.SuppfilleMapper;
import com.iemes.mapper.quality.CheckMaterialMapper;
import com.iemes.plugin.PageView;
import com.iemes.util.Common;

@RequestMapping("/quality")
@Controller
public class CheckMaterialController extends BaseController{

	@Inject
	private CheckMaterialMapper checkMateialMapper;
	
	@Inject
	private SuppfilleMapper suppfilleMapper;
	
	@RequestMapping("checkMaterial")
	private String fine(Model model){
		model.addAttribute("res", findByRes());
		
		//下拉框显示供应商名称
		SuppFilleFromMap suppFilleFromMap=getFormMap(SuppFilleFromMap.class);
		List<Map<String,Object>> suppFilleFromMaps=suppfilleMapper.getAllName(suppFilleFromMap);
		model.addAttribute("suppFilleFromMaps", suppFilleFromMaps);
		return Common.BACKGROUND_PATH + "/quality/checkmaterial/checkMaterial_list";
	}
	
	
	@ResponseBody
	@RequestMapping("checkMaterial_findByPage")
	public PageView findByPage(String pageNow, String pageSize) throws Exception 
	{
		CheckMaterialFormMap checkMaterialFormMap=getFormMap(CheckMaterialFormMap.class);
		List<Map<String,Object>> checkMaterialFormMaps=checkMateialMapper.getCheckMaterialByCondition(checkMaterialFormMap);
		LuogicPaging(pageNow, pageSize,checkMaterialFormMaps);
		return pageView;
	}
	
	@ResponseBody
	@RequestMapping(value="checkMaterial_deleteEntity")
	@SystemLog(module="来料检验",methods="来料检验-删除")//凡需要处理业务逻辑的.都需要记录操作日志
	public String deleteEntity() throws Exception {
		CheckMaterialFormMap checkMaterialFormMap=getFormMap(CheckMaterialFormMap.class);
		String[] ids = getParaValues("ids");
		String arr=ids[0];
		String[] str=arr.split(",");
		for(int i=0;i<str.length;i++){
			checkMaterialFormMap.put("state", 1);
			checkMaterialFormMap.put("id", str[i]);
			baseMapper.editEntity(checkMaterialFormMap);
		}
		return "success";
	}
	
	@RequestMapping("checkMaterial_addUI")
	public String addUI(Model model) throws Exception {
		//下拉框显示供应商名称
		SuppFilleFromMap suppFilleFromMap=getFormMap(SuppFilleFromMap.class);
		List<Map<String,Object>> suppFilleFromMaps=suppfilleMapper.getAllName(suppFilleFromMap);
		model.addAttribute("suppFilleFromMaps", suppFilleFromMaps);
		return Common.BACKGROUND_PATH + "/quality/checkmaterial/checkMaterial_add";
	}
	
	
	@ResponseBody
	@RequestMapping("checkMaterial_addEntity")
//	@Transactional(readOnly=false)//需要事务操作必须加入此注解
	@SystemLog(module="来料检验",methods="来料-新增物料")//凡需要处理业务逻辑的.都需要记录操作日志
	public String addEntity() throws Exception {
		CheckMaterialFormMap checkMaterialFormMap=getFormMap(CheckMaterialFormMap.class);
		checkMaterialFormMap.put("state", 0);
		checkMateialMapper.addEntity(checkMaterialFormMap);
		return "success";
	}
	
	@RequestMapping("checkMaterial_edit")
	public String editUI(Model model) throws Exception 
	{
		String id = getPara("id");
		CheckMaterialFormMap checkMaterialFormMap=checkMateialMapper.getCheckMaterialById(Integer.parseInt(id));
		model.addAttribute("checkMaterialFormMap", checkMaterialFormMap);
		
		//下拉框显示供应商名称
		SuppFilleFromMap suppFilleFromMap=getFormMap(SuppFilleFromMap.class);
		List<Map<String,Object>> suppFilleFromMaps=suppfilleMapper.getAllName(suppFilleFromMap);
		model.addAttribute("suppFilleFromMaps", suppFilleFromMaps);
		
		return Common.BACKGROUND_PATH + "/quality/checkmaterial/checkMaterial_edit";
	}
		
	@ResponseBody
	@RequestMapping(value="checkMaterial_editEntity")
	@SystemLog(module="来料",methods="来料-修改")//凡需要处理业务逻辑的.都需要记录操作日志
	public String editEntity() throws Exception {
		CheckMaterialFormMap checkMaterialFormMap=getFormMap(CheckMaterialFormMap.class);
		checkMateialMapper.editEntity(checkMaterialFormMap);
		return "success";
	}
	
}
